<template>
  <div class="alertPage" v-if="pageShow">
    <div class="part1">
      <div class="part13">
        <u-icon name="info-circle"></u-icon>
        <span class="part131">{{ title }}</span>
      </div>
      <div class="part11">{{ msg }}</div>
      <div class="part12">
        <div class="part121" @click="clickBtn(1)" v-if="cancelBtn">
          <u-icon name="close"></u-icon>
        </div>
        <div class="part121" @click="clickBtn(2)">
          <u-icon name="checkmark"></u-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      pageShow: false,
      title: '提示',
      msg: '恭喜获得一元立减金',
      cancelBtn: true,
      success: null,
      fail: null,
    }
  },
  methods: {
    show(i) {
      if (i) {
        this.title = i.title || '提示'
        this.msg = i.msg || '恭喜获得一元立减金'
        this.cancelBtn = i.cancelBtn === true ? true : false
        this.success = i.success || null
        this.fail = i.fail || null
      }
      this.pageShow = true
    },
    clickBtn(i) {
      if (i === 2) {
        if (this.success) {
          this.success()
        }
      }
      if (i === 1) {
        if (this.fail) {
          this.fail()
        }
      }
      this.remove()
    },
    remove() {
      this.pageShow = false
    },
  },
}
</script>

<style lang="scss" scoped>
.alertPage {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  .part1 {
    width: 280px;
    color: #333;
    text-align: center;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
  }

  .part11 {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    padding: 20px 10px;
    line-height: 1.2;
    background: #fff;
  }

  .part12 {
    padding-bottom: 10px;
    display: flex;
    justify-content: space-around;
    width: 60%;
    margin: 0 auto;
  }

  .part121 {
    background: rgba(255, 0, 0, 0.6);
    color: #fff;
    font-size: 14px;
    padding: 4px 20px;
    border-radius: 6px;
  }

  .part13 {
    background: rgba(255, 0, 0, 0.7);
    color: #fff;
    height: 38px;
    line-height: 38px;
    font-size: 18px;
  }

  .part131 {
    margin-left: 6px;
  }
}
</style>
